/**
 * 
 */
package org.okhati.www.model;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import jxl.Cell;

import org.okhati.www.model.Employee.Sex;

/**
 * @author sujan
 *
 */
public class EmployeeFactory implements Factory<Employee> {

	@Override
	public Employee getFactoryObject(Cell[] cells) {
		Employee employee = new Employee();

		employee.setId(Integer.parseInt(cells[0].getContents()));
		employee.setSn(Integer.parseInt(cells[1].getContents()));
		employee.setPin(Integer.parseInt(cells[2].getContents()));
		employee.setSalutation(cells[3].getContents());
		employee.setName(cells[4].getContents());
		employee.setDob(getDate(cells[5].getContents()));
		employee.setSex(Sex.getSex(cells[6].getContents()));
		employee.setPost(cells[7].getContents());
		employee.setCategory(cells[8].getContents());
		employee.setFaculty(cells[9].getContents());
		employee.setSubFaculty(cells[10].getContents());
		employee.setClassNo(Integer.parseInt(cells[11].getContents()));
		employee.setLevel(cells[12].getContents());
		employee.setStartDate(getDate(cells[13].getContents()));
		//		employee.setInstitution(cells[14].getContents());
		employee.setHiredDate(getDate(cells[15].getContents()));
		employee.setEntryPost(cells[16].getContents());
		employee.setAttendDate(getDate(cells[17].getContents()));
		//		employee.setPreviousInstitution(cells[18].getContents());
		employee.setServicePeriod(Integer.parseInt(cells[19].getContents()));
		employee.setPresentPostPeriod(Integer.parseInt(cells[20].getContents()));
		return employee;
	}

	private Date getDate(String contents) {
		SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy");
		try {
			return formatter.parse(contents);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void main(String[] args) {
		System.out.println(getDate("7/17/06"));
	}


}
